#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unistd.h>
using namespace std;

class Dictionary
{
public:
    Dictionary():_dict(){
    }
    void read(const string &filename){
        ifstream fd(filename);
        if(!fd.good()){
            cerr<<"open error!"<<endl;
            return;
        }
        string word;
        while(fd>>word){
            ++_dict[word];
        }
        fd.close();
    }
    void store(const string &filename){
        ofstream fd(filename);
        for(auto &x:_dict){
            fd<<x.first<<" : "<<x.second<<endl;
        }
        fd.close();
    }
    void print(){
        
    }
private:
    unordered_map<string,int> _dict;
};  

int main()
{
    string readFile("/home/snower/me/study/code/C_Pro_Learn/c++/files/The_Holy_Bible.txt");
    //string readFile("test.txt");
    string outFile("Holy_Dictionary2.txt");
    Dictionary Holy_Dictionary;
    Holy_Dictionary.read(readFile);
    //Holy_Dictionary.print();
    Holy_Dictionary.store(outFile);

    return 0;
}

